package com.toby.service.impl;

import com.toby.dao.UserDao;
import com.toby.entity.User;
import com.toby.service.LogService;
import com.toby.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @desc: 用户Service
 * @author: toby
 * @date: 2019/10/8 23:18
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private LogService logService;
    @Override
    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void addUser(User user) {
        userDao.addUser(user.getName(),user.getSex(),user.getAddress());
        //演示Propagation.NESTED 内嵌事务不影响外部事务
        try {
            logService.addLog("新增用户");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
